//###############
//FILE : WantFileRequest.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############
package oop.ex3.filemanager;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import oop.ex3.communication.Request;
import oop.ex3.protocol.sessions.FileRequestSession;

/**
 * This is specialized Request that handles WantFile requests from othe FM. It has access to the FM
 * database in order to look up the file and send it.
 * @author daniel
 */
public class WantFileRequest extends Request {
    private FileDatabase _fileDatabase;

    /**
     * Create a new request with a certain DB.
     * @param fileDatabase
     */
    public WantFileRequest(FileDatabase fileDatabase) {
        super (new FileRequestSession());
        _fileDatabase = fileDatabase;
    }

    @Override
    public Request getCopy() {
        return new WantFileRequest(_fileDatabase);
    }

    @Override
    public boolean serveRequest(DataInputStream inputStream, DataOutputStream outputStream) {
       //System.out.println("serving file request");
       
       ((FileRequestSession)_openingSession).setFileDatabase(_fileDatabase);
       return _openingSession.executeSession(inputStream, outputStream);
    }

}
